<template>
    <div class="app-container">
    <levelbar></levelbar>
        <div class="content">
            <TableLayout form-title="">
            <div slot="form-title" class="table-title"></div>
                <div class="form-title" slot="oder-info">               
                    <el-row class="infomation">
                        <el-col :span="6" class='boder-right'>
                            <div class="info-name">订单号</div>
                            <div class="info-num">{{orderNum}}</div>
                        </el-col>
                        <el-col :span="4" :offset="1">
                            <div class="info-name">待发放</div>
                            <div class="info-num">{{unIssued}}</div>
                        </el-col> 
                        <el-col :span="4">
                            <div class="info-name">已发放</div>
                            <div class="info-num">{{issued}}</div>
                        </el-col>
                        <el-col :span="4">
                            <div class="info-name">待激活</div>
                            <div class="info-num">{{unActivation}}</div>
                        </el-col>
                        <el-col :span="4">
                            <div class="info-name">已激活</div>
                            <div class="info-num">{{activation}}</div>
                        </el-col>
                    </el-row>
                </div>
                <el-form :model="formInline" class="formInline" label-width="100px"  ref="formInline" slot="form" :rules="rules">          
                    <el-row :gutter="41">
                        <el-col :span="8">
                            <el-form-item label="激活码状态">
                                <el-select v-model="formInline.codeStatus" style="width:100%" >
                                    <el-option v-for="item in codeStatusList" :key="item.orgId" :label="item.statusName" :value="item.orgId"> </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col> 
                        <el-col :span="8">
                            <el-form-item label="激活码" prop="activationCode">
                                <el-input v-model="formInline.activationCode" placeholder="请输入内容" :maxlength="12"></el-input>
                            </el-form-item>
                        </el-col> 
                        <el-col :span="8">
                            <el-form-item label="发放手机号" prop="issuedPhone">
                                <el-input v-model="formInline.issuedPhone" placeholder="请输入内容" :maxlength="11"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="41">
                        <el-col :span="8">
                            <el-form-item label="激活手机号" prop="activationPhone">
                                <el-input v-model="formInline.activationPhone" placeholder="请输入内容" :maxlength="11"></el-input>
                            </el-form-item>
                        </el-col>                  
                    </el-row>
                    <div class="top-line">
                        <el-button type="primary" @click="onSubmit('formInline')">查询</el-button>
                    </div>
                </el-form>
                
                <div class="table-title" slot="table-title">               
                </div>
                <el-table :data="dataApply" style="width: 100%" border v-loading="loading" ref="multipleTable">
    
                    <el-table-column label="激活码" align="center"  prop="schoolName">
                        <template scope="scope">
                            <span>{{scope.row.activationCode | isNull}}</span>
                        </template>
                    </el-table-column>
                    
                    <el-table-column label="发放状态" align="center" prop="schoolType">
                        <template scope="scope">
                            <span>{{scope.row.issuedStatus=='0' ? '待发放' : '已发放'}}</span>
                        </template>
                    </el-table-column>
    
                    <el-table-column label="发放手机号" align="center" prop="belongToArea">
                        <template scope="scope">
                            <span>{{scope.row.issuedPhone | isNull}}</span>
                        </template>
                    </el-table-column>
                    
                    <el-table-column label="发放时间" align="center" prop="detail">
                        <template scope="scope">
                            <span>{{scope.row.issuedTime | isNull}}</span>
                        </template>
                    </el-table-column>
                    
                    <el-table-column label="激活状态" align="center" prop="createTime"> 
                        <template scope="scope">
                            <span v-if="!scope.row.activationStatus">--</span>
                            <span v-if="scope.row.activationStatus">{{scope.row.activationStatus=='0' ? '待激活' : '已激活'}}</span>
                        </template>
                    </el-table-column>
                    
                    <el-table-column align="center" label="激活手机号" prop="creatorName">
                        <template scope="scope">
                            <span>{{scope.row.activationPhone | isNull}}</span>
                        </template>
                    </el-table-column>
                    
                    <el-table-column label="激活时间" align="center">
                        <template scope="scope">
                            <span>{{scope.row.activationTime | isNull}}</span>
                        </template>                
                    </el-table-column>
                </el-table>
                <div class="pagination-container" style="text-align:right">
                    <el-pagination
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="+listQuery.total"
                        :current-page.sync="listQuery.page"
                        :page-sizes="config.pageSizes"
                        :page-size="config.pageSize"
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange">
                    </el-pagination>
                </div>
            </TableLayout>
        </div>
    </div>
</template>
 
<script>
import Levelbar from '../layout/Levelbar';
import {pageActivationDetail, getOrderByCodeId} from 'api/memberMangement';
import TableLayout from './comps/checkCodeTable';
import { mapState, mapActions, mapGetters } from 'vuex';
import province from 'components/CascadeRegion/province';
import city from 'components/CascadeRegion/city';
import region from 'components/CascadeRegion/region';
import school from 'components/SchoolClasss/school';
import validate from '@/utils/validate';
 
export default{
    name: 'checkCode',
    components: {TableLayout, province, city, region, school, Levelbar},
    data() {
        return {
            orderNum: '--',
            unIssued: '--',
            issued: '--',
            unActivation: '--',
            activation: '--',
            formInline: {// form表单数据
                codeStatus: '',
                activationCode: '',
                issuedPhone: '',
                activationPhone: ''
            },
            codeStatusList: [
                {
                    orgId: '',
                    statusName: '请选择'
                },
                {
                    orgId: '0',
                    statusName: '待发放'
                },
                {
                    orgId: '1',
                    statusName: '已发放'
                },
                {
                    orgId: '2',
                    statusName: '待激活'
                },
                {
                    orgId: '3',
                    statusName: '已激活'
                }
            ],
            dataApply: [],
            dataNum: 1, // 表格1显示条数，初始为1
            listQuery: {// 分页
                page: 1,
                total: 0
            },
            rules: {
                issuedPhone: [...validate.phone()],
                activationPhone: [...validate.phone()],
                activationCode: [
                    { max: 12, min: 12, message: '激活码不足12位', trigger: 'blur' }
                ]
            },
            loading: false
        }
    },
   
    computed: {
        ...mapState({
            config: state => state.config.table,
            cacheUpdated: state => state.app.cacheUpdated// 局部刷新列表
        }),
        ...mapGetters([
            'uid'
        ])
    },
    watch: {// 局部刷新列表
        cacheUpdated(val) {
            val && this.searchFetchData();
        }
    },
    // 初始化
    created() {
        this.searchFetchData();
        this.getOrder();
    },
    filters: {
        filterCreateTime(val) {
            if (val) {
                return val.substr(0, val.length-2) 
            } else {
                return '--'
            }
        }
    },
    methods: {
        // 全局获取行数
        ...mapActions(['ChangePageSize']),
        // 分页
        handleSizeChange(val) {
            this.listQuery.page = 1;
            this.loading = true;
            this.ChangePageSize(val);
            this.searchFetchData();
            this.$store.dispatch('UpdateCache', true);// 修改 和查看
        },
        handleCurrentChange(val) {
            this.loading = true;
            this.listQuery.page = val;
            this.searchFetchData();
        },
        // 查询列表
        searchFetchData() {
            this.loading = true;
            pageActivationDetail(this.listQuery.page, this.config.pageSize, this.formInline.codeStatus, this.formInline.activationCode, this.formInline.issuedPhone, this.formInline.activationPhone, this.$route.params.id).then(response => {              
                this.dataApply = response.data.content.list;
                this.listQuery.total = response.data.content.pagination.total;
                this.loading = false;
            });
        },
        getOrder() {
            getOrderByCodeId(this.$route.params.id).then(res => {
                this.orderNum = res.data.content.orderNum;
                this.unIssued = res.data.content.unIssued;
                this.issued = res.data.content.issued;
                this.unActivation = res.data.content.unActivation;
                this.activation = res.data.content.activation;
            });
        },
        // 表单查询
        onSubmit() {
            this.$refs['formInline'].validate((valid) => {
                if (valid) {
                    this.listQuery.page = 1;
                    this.searchFetchData();
                } else {
                    return false;
                }
            });
        }
 
    }
}
</script>
<style lang="scss" scoped>
.app-container {
    position: relative;
    padding: 20px 20px 10px;
}
.content {
    position: relative;
    padding: 0px;
    $bgcolor:#fff;
    label{
        text-align:left;
    }
    .el-tag{
            margin-left:5px;
            background:#f9f9f9;
            color:#444;
        }
    .formInline {
        .formBtn{
            width: 100%;
            height: 70px;
            border-top: 1px solid #dddddd;
            position: relative;
            .btnPosition{
                position: absolute;
                right:0px; 
                top: 18px;
            }
        }
    }
    .table-box{
        color: #333;
        font-size: 14px;
        padding: 10px 0;
        line-height: 20px;
    }
    .info-name{
        font-size: 18px;
        color: #999;
        padding-bottom:33px
    }
    .info-num{
        font-size: 23px;
        color: #343434;
    }
    .infomation{
        width:100%;
        text-align:center;
    }
    .boder-right{
        border-right: 2px solid #ccc;
    }
}
</style>